﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            //  RecursiaIsCrap1(5);
            //  RecursiaIsCrap(5);
            int[] ar = { 100, 2, 5, -13, 0, 2 };
            string s = "123456789";
            /* char[] chars = StringRec(s);
             foreach (var elem in chars)
             {
                 Console.Write(elem);
             }
             Console.WriteLine();*/

            /* char[] chars1 = StringRecReverse(s);
             foreach (var elem in chars1)
             {
                 Console.Write(elem);
             }
             Console.WriteLine();*/
            //  int min = FindMin(ar);
            //  Console.WriteLine("min element of array:  "+min);
            PrintString(s);
            Console.WriteLine();
            PrintString2(s);
            Console.WriteLine();
            PrintString2(s, 0);
            Console.WriteLine();
        }

        static void PrintString(string s)
        {
            PrintOdd(s, 0);
            PrintEven(s, 1);
        }

        static void PrintEven(string s, int indexEven)
        {
            if (indexEven >= s.Length)
            {
                return;
            }
            Console.Write(s[indexEven]);
            indexEven = indexEven + 2; ;
            PrintEven(s, indexEven);
        }


        static void PrintOdd(string s, int indexOdd)
        {
            if (indexOdd >= s.Length)
            {
                return;
            }
            Console.Write(s[indexOdd]);
            indexOdd = indexOdd + 2;
            PrintEven(s, indexOdd);
        }

        static void PrintString2(string s)
        {
            PrintOdd2(s, 0);

            int indexEven = -1;
            if (s.Length % 2 == 0)
            {
                indexEven = s.Length - 1;
            }
            else
            {
                indexEven = s.Length - 2;
            }
            PrintEven2(s, indexEven);
        }

        static void PrintOdd2(string s, int indexOdd)
        {
            if (indexOdd > s.Length - 1)
            {
                return;
            }
            Console.Write(s[indexOdd]);
            indexOdd = indexOdd + 2;
            PrintOdd2(s, indexOdd);
        }

        static void PrintEven2(string s, int indexEven)
        {
            if (indexEven < 1)
            {
                return;
            }
            Console.Write(s[indexEven]);
            indexEven = indexEven - 2; ;
            PrintEven2(s, indexEven);
        }

        static void PrintString2(string s, int ind)
        {
            if (ind >= s.Length)
            {
                return;
            }

            Console.Write(s[ind]);
            Console.WriteLine("Down");
            PrintString2(s, ind + 2);
            Console.WriteLine("Up");
            if (ind + 1 < s.Length)
            {
                Console.Write(s[ind+1]);
            }
        }


        static char[] StringRec(string s)
        {
            char[] chars = new char[s.Length];
            int secondIndexChar = 0;
            if (s.Length % 2 == 0)
            {
                secondIndexChar = s.Length / 2;
            }
            else
            {
                secondIndexChar = s.Length / 2 + 1;
            }
            chars = StringInnerRec(chars, s, 0, 0, secondIndexChar);
            return chars;
        }

        static char[] StringInnerRec(char[] chars, string s, int index, int indexChar, int secondIndexChar)
        {
            if (index == s.Length)
            {
                return chars;
            }
            if (index % 2 == 0)
            {
                chars[indexChar] = s[index];
                indexChar++;
            }
            else
            {
                chars[secondIndexChar] = s[index];
                secondIndexChar++;
            }
            index++;
            chars = StringInnerRec(chars, s, index, indexChar, secondIndexChar);

            return chars;
        }

        static char[] StringRecReverse(string s)
        {
            char[] chars = new char[s.Length];
            chars = StringInnerRecReverse(chars, s, 0, 0, s.Length);
            return chars;
        }

        static char[] StringInnerRecReverse(char[] chars, string s, int index, int indexChar, int endIndex)
        {
            if (index == s.Length)
            {
                return chars;
            }
            if (index % 2 == 0)
            {
                chars[indexChar] = s[index];
                indexChar++;
            }
            else
            {
                chars[endIndex - 1] = s[index];
                endIndex--;
            }
            index++;
            chars = StringInnerRecReverse(chars, s, index, indexChar, endIndex);

            return chars;
        }

        static void RecursiaIsCrap(int n)
        {
            if (n <= 0)
            {
                return;
            }

            RecursiaIsCrap(n - 1);
            Console.WriteLine(n + "  Olya");
        }

        static void RecursiaIsCrap1(int n)
        {
            Console.WriteLine(n + "  Sergey");
            if (n > 0)
            {
                RecursiaIsCrap1(n - 1);


            }
        }
        static public int FindMin(int[] ar)
        {
            int min = ar[0];

            min = FindMinRec(ar, min, 1);
            return min;
        }

        static int FindMinRec(int[] ar, int min, int index)
        {

            if (index == ar.Length - 1)
            {
                return min;
            }
            if (ar[index] < min)
            {
                min = ar[index];
            }
            index++;
            min = FindMinRec(ar, min, index);
            return min;
        }

        public static long fact(int n)
        {
            long res = 0;
            if (n == 0)
            {
                res = 1;
            }
            else
            {
                res = n * fact(n - 1);
            }
            return res;
        }
    }
}
